package com.example.administrator.yunniuusedcar.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.administrator.common.base.BaseFragment;
import com.example.administrator.common.base.Global;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.adapter.ZhongGuiCar_jiaGeAdapter2;
import com.example.administrator.yunniuusedcar.adapter.ZhongGuiCar_xiaoLiangAdapter2;
import com.example.administrator.yunniuusedcar.holder.ZgEquatorCar_JiaGe_Bean;
import com.example.administrator.yunniuusedcar.holder.ZgEquatorCar_XiaoLiang_Bean;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;

import okhttp3.Call;

/**
 * Created by Administrator on 2017/12/7.
 *  价格排序
 */

public class PriceSortFragment extends BaseFragment {

    private RecyclerView recyclerView9;
    private ZhongGuiCar_jiaGeAdapter2 jiaGeAdapter2;

    @Override
    public int getLayoutRes() {
        return R.layout.fragment_zonghepaixu;
    }

    @Override
    public void initView() {
        initUloadMenuInfor5();

        initRecycleV();
    }
    private void initRecycleV() {

        recyclerView9 = findView(R.id.recycler_view6);

        recyclerView9.setLayoutManager(new LinearLayoutManager(mActivity));

        //创建数据
        listDatas = new ArrayList();

//        zhongGuiCarZongHeAdapter1 = new ZhongGuiCar_zongHeAdapter(getContext(),
//                R.layout.fragment_zonghepaixu,listDatas);
        jiaGeAdapter2 = new ZhongGuiCar_jiaGeAdapter2(getContext(),listDatas);
        recyclerView9.setAdapter(jiaGeAdapter2);
        initUloadMenuInfor5();    //// (  加载数据 )
/////
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }


    ArrayList listDatas = new ArrayList();

    private void initUloadMenuInfor5() {    // 价格数据

        String ul = IHttpService.HOST_URL + "Car/typeCar" ;    // 销量排序

        OkHttpUtils.post().url(ul).addParams("sign",IHttpService.SignVal).addParams("page","1").addParams("num","3")
                .addParams("type","3").addParams("type_id","1").build().execute(new StringCallback() {     //.addParams("type","1")   价格排序

            @Override
            public void onError(Call call, Exception e, int id) {
                          Global.showToast("中规豪车、价格排序，请求超时！"+ e.getMessage());
                //      System.out.println("-----====----------A"+ e);
            }

            @Override
            public void onResponse(String response, int id) {
                ////        Global.showToast("====="+response);
                //      System.out.println("-----====-----------A1"+response);
                Gson js = new Gson();
                ZgEquatorCar_JiaGe_Bean wzArticleInfoBean = js.fromJson(response,ZgEquatorCar_JiaGe_Bean.class);
                listDatas.add(wzArticleInfoBean);
                // 需刷新
                jiaGeAdapter2.notifyDataSetChanged();

            }
        });
    }
}
